package com.example.myrecycleviewsmoth;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tgw
 * @date 2021/1/19
 */
public class RvAdapter extends RecyclerView.Adapter<RvAdapter.MyViewHolder> {

    private List<String> mData ;
    private Context context;

    public RvAdapter(Context context) {
        this.context = context;
        mData = new ArrayList<>();
    }

    public void setData(List<String> data) {
        if (mData.size() > 0) {
            mData.clear();
        }
        if (data != null && data.size() > 0) {
            this.mData.addAll(data);
        }
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.leke_th_incentive_dress_item_layout, parent, false);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.tvCurson.setText(mData.get(position));
    }


    @Override
    public int getItemCount() {
        return mData != null ? mData.size() : 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView tvCurson;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            tvCurson=itemView.findViewById(R.id.tv_content);
        }


    }
}
